package com.terry.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

private static String PATTERN = "yyyy-MM-dd HH:mm:ss";
	
	public static void main(String[] args) {
		String date = "2016-7-4 10:10";
		System.out.println(parseDate(date));
	}
	
	public static String formatDate(Date date) {
		return formatDate(date,PATTERN);
	}
	public static String formatDate(Date date, String pattern) {
		SimpleDateFormat df = new SimpleDateFormat(pattern);
		return df.format(date);
	}
	
	public static Date parseDate(String date) {
		return parseDate(date, PATTERN);
	}
	
	public static Date parseDate(String date, String pattern) {
		SimpleDateFormat df = new SimpleDateFormat(pattern);
		try {
			return df.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
}
